<!DOCTYPE html>
<!--
    Licensed to the Apache Software Foundation (ASF) under one
    or more contributor license agreements.  See the NOTICE file
    distributed with this work for additional information
    regarding copyright ownership.  The ASF licenses this file
    to you under the Apache License, Version 2.0 (the
    "License"); you may not use this file except in compliance
    with the License.  You may obtain a copy of the License at

    http://www.apache.org/licenses/LICENSE-2.0

    Unless required by applicable law or agreed to in writing,
    software distributed under the License is distributed on an
    "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
     KIND, either express or implied.  See the License for the
    specific language governing permissions and limitations
    under the License.
-->
<html>
    <head>
        <meta charset="utf-8">
        <meta http-equiv="Content-Security-Policy" content="default-src 'self' data: https://ssl.gstatic.com 'unsafe-eval'; style-src 'self' 'unsafe-inline'; media-src *; img-src 'self' data: content:;">
        <meta name="format-detection" content="telephone=no">
        <meta name="msapplication-tap-highlight" content="no">
        <meta name="viewport" content="initial-scale=1, width=device-width, viewport-fit=cover">
        <meta name="color-scheme" content="light dark">
        <link rel="stylesheet" href="css/index.css">
        <title>电池状态监测</title>
        <style>
            .battery-container {
                max-width: 800px;
                margin: 0 auto;
                padding: 20px;
                background-color: #fff;
                min-height: calc(100vh - 100px);
            }
            .nav {
                background-color: #2c3e50;
                padding: 15px;
                text-align: center;
                margin-bottom: 20px;
            }
            .nav a {
                color: #fff;
                text-decoration: none;
                margin: 0 15px;
                font-size: 16px;
                padding: 8px 15px;
                border-radius: 4px;
                transition: background-color 0.3s;
                display: inline-block;
            }
            .nav a:hover, .nav a.active {
                background-color: #34495e;
            }
            .battery-card {
                background-color: white;
                border-radius: 10px;
                padding: 25px;
                box-shadow: 0 2px 10px rgba(0,0,0,0.1);
                margin-bottom: 20px;
            }
            .battery-title {
                text-align: center;
                color: #333;
                margin-top: 0;
                margin-bottom: 20px;
                font-size: 2em;
            }
            .battery-info {
                font-size: 18px;
                margin: 15px 0;
                color: #555;
                padding: 10px;
                background-color: #f8f9fa;
                border-radius: 6px;
            }
            .battery-level {
                font-size: 32px;
                font-weight: bold;
                text-align: center;
                margin: 20px 0;
                padding: 20px;
                border-radius: 8px;
                background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
                color: white;
            }
            .charge-indicator {
                display: inline-block;
                width: 12px;
                height: 12px;
                border-radius: 50%;
                margin-right: 8px;
            }
            .charging {
                background-color: #4CAF50;
                animation: blink 1.5s infinite;
            }
            .not-charging {
                background-color: #F44336;
            }
            @keyframes blink {
                0% { opacity: 1; }
                50% { opacity: 0.5; }
                100% { opacity: 1; }
            }
            .btn {
                display: block;
                width: 100%;
                padding: 12px;
                margin-top: 15px;
                background-color: #2196F3;
                color: white;
                border: none;
                border-radius: 5px;
                font-size: 16px;
                cursor: pointer;
                transition: background-color 0.2s;
            }
            .btn:hover:not(:disabled) {
                background-color: #1976D2;
            }
            .btn:disabled {
                opacity: 0.6;
                cursor: not-allowed;
            }
            .note {
                font-size: 14px;
                color: #666;
                padding: 15px;
                background-color: #e8f4fd;
                border-radius: 5px;
                margin-top: 20px;
                line-height: 1.6;
            }
            .note strong {
                color: #2196F3;
            }
            .event-log {
                margin-top: 20px;
                padding: 15px;
                background-color: #f8f9fa;
                border-radius: 6px;
                max-height: 200px;
                overflow-y: auto;
            }
            .event-log h3 {
                margin-top: 0;
                color: #333;
                font-size: 16px;
            }
            .event-item {
                font-size: 12px;
                color: #666;
                padding: 5px 0;
                border-bottom: 1px solid #e0e0e0;
            }
            .event-item:last-child {
                border-bottom: none;
            }
            @media (max-width: 768px) {
                .nav a {
                    display: block;
                    margin: 5px 0;
                }
                .battery-title {
                    font-size: 1.5em;
                }
                .battery-level {
                    font-size: 24px;
                }
            }
        </style>
    </head>
    <body>
        <div class="nav">
            <a href="index.html">首页</a>
            <a href="about.html">关于我们</a>
            <a href="poem.html">藏头诗</a>
            <a href="translate.html">翻译</a>
            <a href="express.html">快递查询</a>
            <a href="ip.html">IP查询</a>
            <a href="workday.html">工作日查询</a>
            <a href="network.html">网络状态</a>
            <a href="vibrate.html">震动功能</a>
            <a href="battery.html" class="active">电池状态</a>
        </div>
        <div class="battery-container">
            <div class="battery-card">
                <h1 class="battery-title">🔋 设备电池状态监测</h1>
                <div class="battery-level" id="batteryLevel">电量：获取中...</div>
                <div class="battery-info" id="chargeStatus">充电状态：获取中...</div>
                <div class="battery-info" id="timeInfo">时间预估：获取中...</div>
                <button id="removeListenerBtn" class="btn">移除电池状态监听</button>
            </div>

            <div class="event-log">
                <h3>📋 事件日志</h3>
                <div id="eventLogContent">
                    <div class="event-item">等待电池状态更新...</div>
                </div>
            </div>

            <div class="note">
                <strong>注意事项：</strong><br>
                1. HarmonyOS 无法获取完整的电池数据（如充电时间、放电时间）。<br>
                2. 电池电量更新频率由系统决定（通常为 1%-5% 电量变化时触发，或充电状态切换时触发）。<br>
                3. 低电量阈值：20%，临界电量阈值：5%。<br>
                4. 若需获取屏幕亮度控制功能，需额外安装 `cordova-plugin-brightness` 插件。
            </div>
        </div>

        <script src="cordova.js"></script>
        <script src="js/utils.js"></script>
        <script src="js/battery.js"></script>
    </body>
</html>

